from selenium import webdriver
from time import time,sleep

class Public:
    def isElementExist(self,element):  # 使用Xpath方式定位元素
        flag = True
        try:
            self.wd.find_element_by_xpath(element)
            return flag
        except:
            flag = False
            return flag

    def openBrower(self):
        self.wd = webdriver.Chrome(r'C:\Program Files\Google\Chrome\Application\chromedriver.exe')

    def openOneKeyPlanWeb(self):
        self.wd.get('http://******************/oneKeyPlan/')
        self.wd.implicitly_wait(10)
        before1 = time()
        mainWindow = self.wd.current_window_handle
        self.wd.find_element_by_xpath('//*[@id="userName"]').send_keys('*********')  # 账户
        after1 = time()
        self.wd.find_element_by_xpath('//*[@id="password"]').send_keys('88kkkkkkkkkk88888kk8888888')  # 密码
        self.wd.find_element_by_xpath('//*[@id="root"]/div/div[2]/div[2]/div/form/div[2]/div/div/div/button').click()  # 点击登录
        sleep(1)
        flag = self.isElementExist('/html/body/div[3]/div/div[2]/div/div[2]/div/div/div[2]/button[2]')  # 使用Xpath方式定位元素

        if flag:
            self.wd.find_element_by_xpath(
                '/html/body/div[3]/div/div[2]/div/div[2]/div/div/div[2]/button[2]').click()  # 登陆提示 点击 继续
        print(after1 - before1)
        sleep(2)

p=Public()